<template>
  <div class="parent" v-if="parentData">
    <div class="user-box">
      <div class="user">
        <img
          :src="$axios.defaults.baseURL + parentData.account.defaultAvatar"
          alt
        />
        <div class="username">{{ parentData.account.nickname }}</div>
        <div class="date">
          {{
            this.$moment(this.parentData.updated_at).format("YYYY-MM-DD hh:mm")
          }}
        </div>
      </div>
      <div class="floor">{{ level - 1 }}</div>
    </div>
    <parent
      :parentData="parentData.parent"
      :level="level - 1"
      @parentReply="diguiparentReply"
    />
    <div class="content">{{ parentData.content }}</div>
    <div class="picData" v-if="parentData.pics.length == 1">
      <img :src="$axios.defaults.baseURL + parentData.pics[0].url" alt />
    </div>
    <div class="picData" v-if="parentData.pics.length == 2">
      <img :src="$axios.defaults.baseURL + parentData.pics[0].url" alt />
      <img :src="$axios.defaults.baseURL + parentData.pics[1].url" alt />
    </div>
    <div class="picData" v-if="parentData.pics.length == 3">
      <img :src="$axios.defaults.baseURL + parentData.pics[0].url" alt />
      <img :src="$axios.defaults.baseURL + parentData.pics[1].url" alt />
      <img :src="$axios.defaults.baseURL + parentData.pics[2].url" alt />
    </div>
    <div class="picData" v-if="parentData.pics.length == 4">
      <img :src="$axios.defaults.baseURL + parentData.pics[0].url" alt />
      <img :src="$axios.defaults.baseURL + parentData.pics[1].url" alt />
      <img :src="$axios.defaults.baseURL + parentData.pics[2].url" alt />
      <img :src="$axios.defaults.baseURL + parentData.pics[3].url" alt />
    </div>
    <div
      class="reply"
      @click="parentReply(parentData.id, parentData.account.nickname)"
    >
      回复
    </div>
  </div>
</template>

<script>

export default {
  data() {
    return {};
  },
  props: ["parentData", "level"],
  name: "parent",
  methods: {
    parentReply(id, nickname) {
      this.$emit("sendParentReply", id, nickname);
    },
    diguiparentReply(parentId, user) {
      this.$emit("parentReply", parentId, user);
    },
  },
};
</script>

<style lang="less" scoped>
.parent {
  width: 95%;
  margin: 10px 20px 0;
  border: 1px solid #ccc;
  padding: 5px 2px;
  display: flex;
  flex-direction: column;
  background-color: #f9f9f9;
  .user-box {
    width: 100%;
    display: flex;
    justify-content: space-between;
    .user {
      display: flex;
      align-items: center;

      .username {
        font-size: 12px;
        color: #666;
        padding: 0 10px;
      }
      .date {
        font-size: 10px;
        color: #666;
      }
      img {
        width: 16px;
        height: 16px;
        border-radius: 8px;
      }
    }

    .floor {
      font-size: 12px;
    }
  }
  .content {
    padding: 10px 0;
  }
  .picData {
    width: 100px;
    height: 100px;
    display: flex;

    img {
      margin-right: 10px;
      width: 100%;
      height: 100%;
    }
  }
  .reply {
    font-size: 12px;
    text-align: right;
    color: #1e50a2;
    visibility: hidden;
    &:hover {
      cursor: pointer;
    }
  }
}
.parent:hover .reply {
  visibility: visible;
}
</style>
